<?php
namespace app\admin\model;
use think\Db;
use think\Model;

class CarModel extends Model
{
    protected $autoCheckFields =false;
	 public function __construct()
	{
		parent::__construct();

	}
	public function getCarList($page,$limit,$map=array(),$field='a.*')
	{
		return Db::name('car_info a')->join(['xm_driver_base'=>'b'],'a.driver_id = b.driver_id','LEFT')
            ->join(['xm_driver_info'=>'c'],'b.driver_id = c.driver_id','LEFT')
			->page($page,$limit)->where($map)->order('car_id desc')->field($field)->select();
	}
	public function getCarById($id,$field='a.*')
	{
		return Db::name('car_info a')->join(['xm_driver_base'=>'b'],'a.driver_id = b.driver_id','LEFT')
            ->join(['xm_driver_info'=>'f'], 'f.driver_id = b.driver_id', 'LEFT')
            ->join('__REGION__ c','c.region_id=f.work_city','LEFT')
            ->join('__REGION__ d','d.region_id=f.work_county','LEFT')
            ->join('__REGION__ e','e.region_id=f.work_province','LEFT')
            ->field($field.",e.region_name as province,c.region_name as city,d.region_name as county")
            ->where('car_id='.$id)->field($field)->find();
	}

	public function searchCar($map,$field)
	{
		return Db::name('car_info a')->join(['xm_driver_base'=>'b'],'a.driver_id = b.driver_id','LEFT')
            ->join(['xm_driver_info'=>'c'],'c.driver_id = b.driver_id','LEFT')
			->where($map)->order('car_id desc')->field($field)->find();
	}

    public function searchCarList($map,$field)
    {
        return Db::name('car_info a')->join(['xm_driver_base'=>'b'],'a.driver_id = b.driver_id','LEFT')
            ->join(['xm_driver_info'=>'c'],'c.driver_id = b.driver_id','LEFT')
            ->where($map)->order('car_id desc')->field($field)->select();
    }
}
